package cn.com.connext.scrm.service;

import cn.com.connext.scrm.config.Constants;
import cn.com.connext.scrm.domain.master.ClickCount;
import cn.com.connext.scrm.domain.master.PrizeGood;
import cn.com.connext.scrm.domain.master.TmpMsgRecord;
import cn.com.connext.scrm.repository.master.ClickCountRepository;
import cn.com.connext.scrm.repository.master.TmpMsgRecordRepository;
import cn.com.connext.scrm.service.dto.JsonResult;
import cn.com.connext.scrm.service.mapper.ClickCountService;
import cn.com.connext.scrm.service.mapper.ProductService;
import cn.com.connext.scrm.service.mapper.TmpMsgRecordService;
import cn.com.connext.scrm.utils.HttpUtils;
import cn.com.connext.scrm.web.rest.ProductResource;
import cn.com.connext.scrm.web.rest.vm.TempSubScribeVm;
import cn.com.connext.scrm.web.rest.vm.Template;
import cn.com.connext.scrm.web.rest.vm.TemplateParam;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ClickCountServiceImpl implements ClickCountService {
    @Autowired
    private ClickCountRepository clickCountRepository;

    @Override
    public void addClickCount(String activityId, String unionId) {
        ClickCount entity = clickCountRepository.findByActivityIdAndUnionId(activityId,unionId);
        if(entity==null){
            entity =new ClickCount();
            entity.setCreateTime(new Date());
            entity.setActivityId(activityId);
            entity.setUnionId(unionId);
            entity.setCount(1);
        }else{
            entity.setCount(entity.getCount()+1);
            entity.setCreateTime(new Date());
        }
        clickCountRepository.save(entity);
    }

    @Override
    public ClickCount findByActivityIdAndUnionId(String activityId, String unionId) {
        return clickCountRepository.findByActivityIdAndUnionId(activityId,unionId);
    }

    @Override
    public void clearClickCount() {
        clickCountRepository.clearClickCount();
    }
}

